<?php

if (!defined('ROOT'))
    die();

class Adminarea_index {

    public function init() {

	$table = '';
	$container = '';

	$i = 0;
	foreach (Adminarea::getInstance()->getAdminInfoRowArray() as $a => $b) {
	    if ($i % 2 == 0) {
		$container = Html::td('<strong>' . $a . '</strong>', 'confclass', 'left', '25%') . Html::td('<em>' . $b . '</em>', 'confclass', 'left', '25%');
	    } else {
		$table .= Html::tr(
				$container . Html::td('<strong>' . $a . '</strong>', 'confclass', 'left', '25%') . Html::td('<em>' . $b . '</em>', 'confclass', 'left', '25%')
		);
		$container = '';
	    }
	    $i++;
	}

	if ($container) {
	    $table .= Html::tr($container . Html::td('', 'confclass', 'left', '25%') . Html::td('', 'confclass', 'left', '25%'));
	}

	Aurus::getInstance()->addContent(Html::table($table));

	Aurus::getInstance()->addContent('<br /><hr /><br />');

	$important_777 = array(
	    '/templates/',
	    '/engine/cache/',
	    '/engine/configs/',
	    '/engine/filedb/',
	    '/engine/system_data/',
	    '/uploads/',
	    '/uploads/avatars/',
	    '/uploads/files/',
	    '/uploads/images/',
	);

	$table = '';
	foreach ($important_777 as $file) {
	    if (is_writable(ROOT . $file)) {
		$table .= Html::tr(
				Html::td($file, 'confclass') .
				Html::td('<span style="color:green">' . __('Папка доступна для запису') . '</span>', 'confclass')
		);
	    } else {
		$table .= Html::tr(
				Html::td($file, 'confclass') .
				Html::td('<span style="color:red">' . __('Папка не доступна для запису') . '</span>', 'confclass')
		);
	    }
	}
	Aurus::getInstance()->addContent(Html::table($table));

	Aurus::getInstance()->addContent('<br /><hr /><br />');

	$log = Log::getLogAsStr();
	if ($log) {
	    //$log = file_get_contents(MAINDIR . '/system_data/error.log');
	    $d = '<div><textarea rows="20" cols="100" style="width:100%">' . $log . '</textarea></div>';
	    $d .= '<a href="' . LINK_ROOT . 'adminarea/?do=cleanlog' . '">' . __('Очистити лог помилок') . '</a>';
	} else {
	    $d = __('Лог помилок пустий');
	}

	Aurus::getInstance()->addContent($d);
    }

}